package com.pap.itemfeignapi;

import com.pap.itemfeignapi.dto.ItemSkuDTO;
import com.pap.obj.vo.response.ResponseVO;
import feign.hystrix.FallbackFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;

@Component
public class ItemSkuServiceFeignFactory implements FallbackFactory<IItemSkuService> {

    private static Logger logger  =  LoggerFactory.getLogger(ItemSkuServiceFeignFactory.class);

    @Override
    public IItemSkuService create(Throwable throwable) {
        //打印下异常 https://github.com/spring-cloud/spring-cloud-netflix/issues/1471
        return new ItemSkuServiceAPIFallback() {
            @Override
            public ResponseVO<ItemSkuDTO> selectOne(String id) {
                logger.error("ItemSkuServiceFeignFactory selectOne error : [{}]", throwable.getMessage());
                return ResponseVO.validfail("error");
            }

            @Override
            public ResponseVO<BigDecimal> selectItemPriceByItemSkuId(String papToken, String papVersion, String itemSkuId) {
                logger.error("ItemSkuServiceFeignFactory selectItemPriceByItemSkuId error : [{}]", throwable.getMessage());
                return ResponseVO.validfail("error");
            }
        };
    }
}